/*
 * @Author: syyao 
 * @Date: 2019-05-17 15:22:41 
 * @Last Modified by:   syyao 
 * @Last Modified time: 2019-05-17 15:22:41 
 */
<style scoped>
    .about {
        text-align: center;
    }

    .hui_input /deep/ .ivu-input {
        border: 0px;
        border-radius: 0px;
        background-color: #f5f5f5 !important;
    }
</style>
<template>
    <div class="about">
        <Input class="hui_input" v-model="formInline.user" size="large" prefix="ios-contact" placeholder="请输入账号"
               style="width: 240px;margin-top: 20px;"/>
        <br/>
        <Input class="hui_input" v-model="formInline.password" size="large" prefix="ios-lock-outline" type="password"
               placeholder="请输入密码" style="width: 240px;margin-top: 20px;"/>
        <br/>
        <VCode v-if="hackReset" v-bind:VCode.sync="vcode" style="width:240px;margin: 20px auto auto;"></VCode>
        <Button type="primary" style="width:240px;margin-top: 20px;height: 35px;margin-bottom:20px;" @click="login">登
            录
        </Button>
    </div>
</template>

<script>
    import cover from "../js/cover";
    import VCode from "./VCode";
    import GetUserInfo from "../js/GetUserInfo";

    export default {
        components: {VCode},
        data() {
            return {
                formInline: {
                    user: '',
                    password: '',
                },
                vcode: false,
                hackReset: true,
            };
        },
        props: {
            initialize: {
                type: Boolean,
                default: false,
            }
        },
        created() {
        },
        mounted() {
        },
        watch: {
            'initialize': function () {
                this.hackReset = false;
                this.$nextTick(() => {
                    this.hackReset = true
                })
            }
        },
        methods: {
            login: function () {
                let _this = this;

                if (this.formInline.user === '') {
                    _this.$Notice.warning({
                        title: '请输入手机号',
                    });
                    return;
                }
                if (this.formInline.password === '') {
                    _this.$Notice.warning({
                        title: '请输入密码',
                    });
                    return;
                }
                if (this.vcode === false) {
                    this.$Message.warning("请完成验证");
                    return;
                }

                let params = new URLSearchParams();
                params.append('username', this.formInline.user);
                params.append('password', cover.Encrypt(this.formInline.password));
                this.http.post(this, '/WebLogin', params).then(function (msg) {
                    if (msg.data.code === '200') {
                        _this.$Message.success('登陆成功');
                        _this.$emit('update:isShow', false);
                        GetUserInfo.getUserInfo(_this);
                    } else {
                        _this.$Message.error(msg.data.message);

                    }
                });
                _this.hackReset = false;
                _this.$nextTick(() => {
                    _this.hackReset = true
                })
                _this.vcode = false;
            }

        }

    }
</script>
